package com.cnn.function.stock.controller;

import com.cnn.base.util.JsonUtil;
import com.cnn.function.stock.pojo.Stock;
import com.cnn.function.stock.pojo.StockInDetails;
import com.cnn.function.stock.service.StockService;
import net.sf.json.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/stock")
public class StockController {
    @Autowired
    private StockService stockService;

    @RequestMapping("/getStock")
    public String getStock() {
        return JsonUtil.success(stockService.getStock());
    }

    @RequestMapping("/getStockById")
    public String getStockById(String id) {
        return JsonUtil.success(stockService.getStockById(Long.valueOf(id)));
    }

    @RequestMapping("addStock")
    public String addStock(Stock stock) {
        stockService.addStock(stock);
        return JsonUtil.success();
    }

    @RequestMapping("updateStock")
    public String updateStock(Stock stock) {
        stockService.updateStcok(stock);
        return JsonUtil.success();
    }

    @RequestMapping("/deleteStock")
    public String deleteStock(String id) {
        stockService.deleteStock(Long.valueOf(id));
        return JsonUtil.success();
    }

    @RequestMapping("/getStockBySku")
    public String getStockBySku(String sku){
        return JsonUtil.success(stockService.getStockBySku(sku));
    }

    @RequestMapping("inToStock")
    public String inToStock(StockInDetails stockInDetails){
        stockService.inToStock(stockInDetails);
        return JsonUtil.success();
    }
}
